/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.domain;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Sander
 */
public class User 
{
    private String firstName;
    private String lastName;
    private String email;
    
    private String username;
    private String password;
    private int gold;
    private boolean loggedIn;
    
    private List<Player> players;
    private int selectedPlayer;
    
    public User(String usrnm, String pw, String fn, String ln, String mail)
    {
        setUsername(usrnm);
        setPassword(pw);
        setFirstName(fn);
        setLastName(ln);
        setEmail(mail);
        players = new ArrayList<Player>();
        setGold(0);
        setSelectedPlayerIndex(-1);
    }
    public User(String usrnm, String pw, String fn, String ln, String mail, List<Player> plrs, int g, int selectedPlayer)
    {
        setUsername(usrnm);
        setPassword(pw);
        setPlayers(plrs);
        setGold(g);
        setFirstName(fn);
        setLastName(ln);
        setEmail(mail);
        setSelectedPlayerIndex(selectedPlayer);
    }

    
    
    public String getPassword() { return password; }
    public final void setPassword(String password) { this.password = password; }
    public List<Player> getPlayers() { return players; }
    public final void setPlayers(List<Player> players) { this.players = players; }
    public void addPlayer(Player p) { this.players.add(p); }
    public String getUsername() { return username; }
    public final void setUsername(String username) { this.username = username; }
    public int getGold() { return gold; }
    public final void setGold(int g) { this.gold = g; }
    public void addGold(int g) { setGold(getGold() + g); }
    public boolean removeGold(int amount)
    {
        if(getGold() < amount)
        {
            return false;
        }
        setGold(getGold() - amount);
        return true;
    }
    public boolean isLoggedIn() { return loggedIn; }
    public final void setLoggedIn(boolean loggedIn) { this.loggedIn = loggedIn; }
    public String getEmail() { return email; }
    public final void setEmail(String email) { this.email = email; }
    public String getFirstName() { return firstName; }
    public final void setFirstName(String firstName) { this.firstName = firstName; }
    public String getLastName() { return lastName; }
    public final void setLastName(String lastName) { this.lastName = lastName; }
    public int getSelectedPlayerIndex() { return selectedPlayer; }
    public final void setSelectedPlayerIndex(int selectedPlayer) { this.selectedPlayer = selectedPlayer; }
    public Player getSelectedPlayer()
    {
        try
        {
            return getPlayers().get(getSelectedPlayerIndex());
        }
        catch(Exception ex)
        {
            return null;
        }
    }
    public Player selectNextActivePlayer()
    {
        int index = getSelectedPlayerIndex();
        index++;
        if(index >= getPlayers().size())
        {
            index = 0;
        }
        setSelectedPlayerIndex(index);
        return getSelectedPlayer();
    }
    public Player selectPreviousActivePlayer()
    {
        int index = getSelectedPlayerIndex();
        index--;
        if(index < 0)
        {
            index = getPlayers().size() - 1;
        }
        setSelectedPlayerIndex(index);
        return getSelectedPlayer();
    }
}
